package ar.edu.unq.tpi.uis.tepe3.dominio;

import java.io.Serializable;
import java.util.List;

import ar.edu.unq.tpi.uis.tepe3.dominio.exception.GrantableModelValidationException;

/**
 * @author dpalazzo
 * @author gpilla <gpilla@unq.edu.ar>
 */
public abstract class Grantable implements Serializable{
	
	private String id;
	private List<Access> privileges;
	private Boolean isNew;
	
	public Grantable(String aId) {
		this.setId(aId);
		this.setIsNew(true);
	}

	public void setId(String aId) {
		this.id = aId;
	}
	
	public String getId() {
		return id;
	}
	
	public void setIsNew(Boolean isNew) {
		this.isNew = isNew;
	}

	public Boolean getIsNew() {
		return isNew;
	}
	
	/**
	 * @param aPrivilege
	 */
	public void addPrivilege(Access aPrivilege){
		this.privileges.add(aPrivilege);
	}
	
	/**
	 * @param aPrivilege
	 * @return
	 */
	public Boolean hasPrivilege(Access aPrivilege){
		return this.privileges.contains(aPrivilege);
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return this.getId();
	}
	
	//FIXME: ME parece poco feliz que quede aca!
	public Grantable createNew() {
		return this;
	}
	
	public void validate() throws GrantableModelValidationException {
		// throw new GrantableModelValidationException("fallo por que si!");
	}
	
}